
var Live;
var Swallow;
var Playback;
var Cfgbasic;
var Cfgosd;
var totalPage = 0;		//回放录像查询总页数
var currentPage = 0;		//当前页码
var downloadProgress;
var result;
var interval = null;
var g_mapNVSize = new Map();
var g_mapPVSize = new Map();
var totalTime;
var PlayBackType = 0;	//0：本地文件和远程文件模式	1：远程时间模式
var StartTimeStamp;
var StopTimeStamp;
var volume = $("#live_volume_progress").slider({ width: 180, sliderDotSize: 16, barHeight: 6 });
var downloadstate = -1;

function initVideoSizemap () {
  g_mapNVSize.set(0, "QCIF(176x120)");
  g_mapNVSize.set(1, "HCIF(352x120)");
  g_mapNVSize.set(2, "CIF(352x240)");
  g_mapNVSize.set(3, "2CIF(704x288)");
  g_mapNVSize.set(4, "4CIF(704x576)");
  g_mapNVSize.set(5, "2CIF(704x288)");
  g_mapNVSize.set(6, "QVGA(320x240)");
  g_mapNVSize.set(7, "VGA(640x480)");
  g_mapNVSize.set(8, "HVGA(640x240)");
  g_mapNVSize.set(9, "720P(1280x720)");
  g_mapNVSize.set(10, "960P(1280x960)");
  g_mapNVSize.set(11, "UXGA(1600x1200)");
  g_mapNVSize.set(12, "1080P(1920x1080)");
  g_mapNVSize.set(13, "QXGA(2048x1536)");

  g_mapNVSize.set(256, "QHD(960x540)");
  g_mapNVSize.set(512, "960H(960x480)");
  g_mapNVSize.set(528, "1440P(2560x1440)");
  g_mapNVSize.set(544, "4.0MP(2592x1520)");
  g_mapNVSize.set(560, "WUXGA(1920x1200)");
  g_mapNVSize.set(768, "5.0MP(2448x2048)");
  g_mapNVSize.set(1024, "5.0MP(2560x1920)");
  g_mapNVSize.set(1040, "5.0MP(2592*1944)");
  g_mapNVSize.set(1056, "5.0MP(2592*2048)");
  g_mapNVSize.set(1072, "5.0MP(2528*2128)");
  g_mapNVSize.set(1280, "5.0MP(2560x2048)");
  g_mapNVSize.set(1536, "6.0MP(2752*2208)");
  g_mapNVSize.set(1552, "6.0MP(3008*2008)");
  g_mapNVSize.set(1568, "6.0MP(3408*2008)");
  g_mapNVSize.set(1792, "7.0MP(3392*2008)");
  g_mapNVSize.set(2048, "8.0MP(3840*2160)");
  g_mapNVSize.set(2064, "8.0MP(3264x2448)");
  g_mapNVSize.set(2080, "8.0MP(3296x2472)");

  g_mapPVSize.set(0, "QCIF(176x144)");
  g_mapPVSize.set(1, "HCIF(352x144)");
  g_mapPVSize.set(2, "CIF(352x288)");
  g_mapPVSize.set(3, "2CIF(704x288)");
  g_mapPVSize.set(4, "4CIF(704x576)");
  g_mapPVSize.set(5, "2CIF(704x288)");
  g_mapPVSize.set(6, "QVGA(320x240)");
  g_mapPVSize.set(7, "VGA(640x480)");
  g_mapPVSize.set(8, "HVGA(640x240)");
  g_mapPVSize.set(9, "720P(1280x720)");
  g_mapPVSize.set(10, "960P(1280x960)");
  g_mapPVSize.set(11, "UXGA(1600x1200)");
  g_mapPVSize.set(12, "1080P(1920x1080)");

  g_mapPVSize.set(13, "QXGA(2048x1536)");
  g_mapPVSize.set(256, "QHD(960x540)");
  g_mapPVSize.set(512, "960H(960x480)");
  g_mapPVSize.set(528, "1440P(2560*1440)");
  g_mapPVSize.set(544, "4.0MP(2592x1520)");
  g_mapPVSize.set(560, "WUXGA(1920x1200)");
  g_mapPVSize.set(768, "5.0MP(2448x2048)");
  g_mapPVSize.set(1024, "5.0MP(2560x1920)");
  g_mapPVSize.set(1040, "5.0MP(2592*1944)");
  g_mapPVSize.set(1056, "5.0MP(2592*2048)");
  g_mapPVSize.set(1072, "5.0MP(2528*2128)");
  g_mapPVSize.set(1280, "5.0MP(2560x2048)");
  g_mapPVSize.set(1536, "6.0MP(2752*2208)");
  g_mapPVSize.set(1552, "6.0MP(3008*2008)");
  g_mapPVSize.set(1568, "6.0MP(3408*2008)");
  g_mapPVSize.set(1792, "7.0MP(3392*2008)");
  g_mapPVSize.set(2048, "8.0MP(3840*2160)");
  g_mapPVSize.set(2064, "8.0MP(3264x2448)");
  g_mapPVSize.set(2080, "8.0MP(3296x2472)");
  g_mapPVSize.set(1116211456, "3MP(2304x1296)");
  g_mapPVSize.set(1085538944, "(640x360)");
}
// 初始化直播以及预览窗体
$(window).load(function () {
  //默认初始化窗体
  Live = new NT._VActiveX('live_left', 4, 4, 'live_left_content');
  Playback = new NT._VActiveX('playback_left', 2, 2, 'playback_left_content');
  Cfgbasic = new NT._VActiveX('cfgbasic_left', 1, 1, 'cfgbasic_left_content');
  Cfgosd = new NT._VActiveX('cfgosd_left', 1, 1, 'cfgosd_left_content');

  //预览页面变量定义、初始化
  $('#live_ptz_preset_list').empty();
  for (var i = 1; i <= 256; i++) {
    var optText = "Preset " + (i);
    $('#live_ptz_preset_list').append($("<option/>", { value: i, text: optText }));
  }
  document.getElementById("dev_logoff").setAttribute("disabled", true);
  document.getElementById("dev_logoff").style.backgroundColor = '#555555';//设置背景色

  //回放页面变量定义、初始化
  var time = new Date();
  time = moment(time).format('YYYY-MM-DD');
  var querystarttime = time + ' ' + "00:00:00";
  var querystopttime = time + ' ' + "23:59:59";
  $('#back_start_time').val(querystarttime);
  $('#back_stop_time').val(querystopttime);

  //配置界面变量初始化
  initVideoSizemap();
  //登陆
  $("#dev_login").on('click', function () {
    var CanLogin = true;
    //IP，通道，账号，密码未输入报错
    $('.login-input').each(function () {
      if (CanLogin === false) {
        return;
      }
      //参数判断
      if ($(this).val() === "" || $.trim($(this).val()).length === 0) {
        if ($(this).attr("id") === 'live_port') {
          alert('Port number cannot be empty');
          CanLogin = false;
        } else if ($(this).attr("id") === 'live_ip') {
          alert('IP cannot be empty');
          CanLogin = false;
        } else if ($(this).attr("id") === 'live_username') {
          alert('User name cannot be empty');
          CanLogin = false;
        } else {
          alert('User password cannot be empty');
          CanLogin = false;
        }
      }
    });
    //登陆
    if (CanLogin) {
      //调用插件登陆方法
      var devIp = $('#dev_ip').val();	//设备IP
      var userName = $('#dev_username').val(); //用户名
      var userPass = $('#dev_password').val(); //密码
      var devPort = $('#dev_port').val();	//端口号
      var ret = Live.Login(devIp, userName, userPass, devPort);
      if (parseInt(ret) < 0) {
        alert("Login Failed");
        return;
      }
      else {
        //登陆成功后，ip、用户名、密码、端口输入框以及登陆按钮置灰
        document.getElementById("dev_login").setAttribute("disabled", true);
        document.getElementById("dev_login").style.backgroundColor = '#555555';//设置背景色
        document.getElementById("dev_ip").setAttribute("disabled", true);
        document.getElementById("dev_port").setAttribute("disabled", true);
        document.getElementById("dev_username").setAttribute("disabled", true);
        document.getElementById("dev_password").setAttribute("disabled", true);
        document.getElementById("dev_logoff").removeAttribute("disabled");
        document.getElementById("dev_logoff").style.backgroundColor = '#009688';//设置背景色
      }
      Playback.Login(devIp, userName, userPass, devPort);
      Cfgbasic.Login(devIp, userName, userPass, devPort);
      Cfgosd.Login(devIp, userName, userPass, devPort);
      //更新预览通道列表
      var chanCount = Live.GetChannelCount();
      $('#live_channel_list').empty();
      $('#cfg_basic_channelno').empty();
      $('#cfg_manager_chan').empty();
      $('#cfg_osd_channelno').empty();
      for (var i = 0; i < chanCount; i++) {
        var chanText = (i + 1) + " channel";
        $('#live_channel_list').append($("<option/>", { value: i, text: chanText }));
        $('#cfg_basic_channelno').append($("<option/>", { value: i, text: chanText }));
        $('#cfg_manager_chan').append($("<option/>", { value: i, text: chanText }));
        $('#cfg_osd_channelno').append($("<option/>", { value: i, text: chanText }));
      }

      //录像查询通道列表
      $('#back_channel_list').empty();
      for (var i = 0; i < chanCount; i++) {
        var chanText = (i + 1) + " channel";
        $('#back_channel_list').append($("<option/>", { value: i, text: chanText }));
      }

      //设置窗口数
      if (chanCount <= 1) {
        Live.SplitScreen(1, 1);
      }
    }
  });

  //登出
  $('#dev_logoff').on('click', function () {
    Live.LogOff();
    Playback.LogOff();
    Cfgbasic.LogOff();
    Cfgosd.LogOff();
    document.getElementById("dev_login").removeAttribute("disabled");
    document.getElementById("dev_login").style.backgroundColor = '#009688';//设置背景色
    document.getElementById("dev_ip").removeAttribute("disabled");
    document.getElementById("dev_port").removeAttribute("disabled");
    document.getElementById("dev_username").removeAttribute("disabled");
    document.getElementById("dev_password").removeAttribute("disabled");
    document.getElementById("dev_logoff").setAttribute("disabled", true);
    document.getElementById("dev_logoff").style.backgroundColor = '#555555';//设置背景色
    if (1 == PlayBackType) {
      CloseBackvolume();
      var value = "00:00:00/00:00:00";
      $('#back_time').html(value);
      $('#back_progress').changewidth(0);
    }
  });


  //重启
  $('#system_config_reboot').on('click', function () {
    var ret = Live.Reboot_Dev();
    if (0 != ret) {
      alert("Reboot Failed!");
    }
    else {
      alert("Rebooting ,Please Wait!");
    }
  });

  var ptzspeed = $("#live_ptz_speed").slider({ width: 215, sliderDotSize: 16, barHeight: 6 });
  ptzspeed.changewidth(50);
  //设置数值
  $('#live_ptz_value').html(50);

  volume.changewidth(0);
  //音量条不允许滑动
  volume.stopChange();
  var backvolume = $("#back_volume_progress").slider({ width: 195, sliderDotSize: 16, barHeight: 6 });
  backvolume.changewidth(0);
  //音量条不允许滑动
  backvolume.stopChange();

  //--------------------------预览界面命令码方法

  //主码流
  $('#live_1st_stream').on('click', function () {
    //先停止之前的播放
    Live.Stop();
    volume.changewidth(0);
    //音量图标置为关闭状态
    $('#live_volume').addClass('live_volume');
    //播放主码流
    var chanNo = $("#live_channel_list").val();	//通道号
    var ret = Live.Play(chanNo, 0);
    if (null == ret) {
      alert("play failed!");
    } else {
      Live.playState = 1;
      //设置窗口对应的通道号
      var iLength = Live.obsInfos;
      for (var i = 0; i < iLength.length; i++) {
        if (Live.obsInfos[i].obsId == Live.obsId) {
          Live.obsInfos[i].channelNo = chanNo;
          Live.obsInfos[i].playState = 1;
        }
      }
    }

  });

  //副码流
  $('#live_2nd_stream').on('click', function () {
    //先停止之前的播放
    Live.Stop();
    volume.changewidth(0);
    //音量图标置为关闭状态
    $('#live_volume').addClass('live_volume');
    //播放副码流
    var chanNo = $("#live_channel_list").val();	//通道号
    var ret = Live.Play(chanNo, 1);
    if (null == ret) {
      alert("play failed!");
    } else {
      Live.playState = 1;
      //设置窗口对应的通道号
      var iLength = Live.obsInfos;
      for (var i = 0; i < iLength.length; i++) {
        if (Live.obsInfos[i].obsId == Live.obsId) {
          Live.obsInfos[i].channelNo = chanNo;
          Live.obsInfos[i].playState = 1;
        }
      }
    }
  });

  //停止播放
  $('#live_stop_play').on('click', function () {
    Live.Stop();
    Live.playState = 0;
    volume.changewidth(0);
    //音量图标置为关闭状态
    $('#live_volume').addClass('live_volume');
    //通道号置为0
    var iLength = Live.obsInfos;
    for (var i = 0; i < iLength.length; i++) {
      if (Live.obsInfos[i].obsId == Live.obsId) {
        Live.obsInfos[i].channelNo = 0;
        Live.obsInfos[i].playState = 0;
        Live.obsInfos[i].isMute = true;
        Live.obsInfos[i].volume = 0;
      }
    }
  });

  //1分屏
  $('#live_screen_1').on('click', function () {
    var ret = Live.SplitScreen(1, 1);
    if (null == ret) {
      alert("SplitScreen failed!");
    }
  });

  //4分屏
  $('#live_screen_4').on('click', function () {
    var ret = Live.SplitScreen(2, 2);
    if (null == ret) {
      alert("SplitScreen failed!");
    }
  });

  //9分屏
  $('#live_screen_9').on('click', function () {
    var ret = Live.SplitScreen(3, 3);
    if (null == ret) {
      alert("SplitScreen failed!");
    }
  });

  //16分屏
  $('#live_screen_16').on('click', function () {
    var ret = Live.SplitScreen(4, 4);
    if (null == ret) {
      alert("SplitScreen failed!");
    }
  });

  //固定窗口比例
  $('#live_fixd_radio').on('click', function () {
    var ret = Live.SetFix();
    if (null == ret) {
      alert("SetFix failed!");
    }
  });

  //适应窗口大小
  $('#live_fit_window').on('click', function () {
    var ret = Live.SetFit();
    if (null == ret) {
      alert("SetFit failed!");
    }
  });

  //全屏
  $('#live_full_screen').on('click', function () {
    if (3 != Live.iLogonState) {
      alert("Please Login");
      return;
    }
    if (1 != Live.playState) {
      return;
    }
    Live.FullScreen();
  });

  //图片抓拍
  $('#live_snapshot').on('click', function () {
    var SnapType = Live.LocalConfigGet(LOCAL_CAPTURE_TYPE);
    var ret = Live.SnapShot(SnapType); //1:bmp 2:jpg
    if (null == ret) {
      alert("SnapShort failed!");
    }
  });

  //开始对讲
  $('#live_talk_start').on('click', function () {
    if (3 != Live.iLogonState) {
      alert("Please Login");
      return;
    }
    //先获取对讲状态
    var ret = Live.MicStatus();
    if (3 == ret) {	//正在对讲
      alert("Talking!");
      return;
    }
    //开启对讲
    ret = Live.MicEnable();
    if (null == ret) {
      alert("MicEnable failed!");
    }
  });

  //结束对讲
  $('#live_talk_stop').on('click', function () {
    if (3 != Live.iLogonState) {
      alert("Please Login");
      return;
    }
    var ret = Live.MicDisable();
    if (null == ret) {
      alert("Stop failed!");
    }
  });

  //开始录像
  $('#live_rec_start').on('click', function () {
    if (3 != Live.iLogonState) {
      alert("Please Login");
      return;
    }
    //先获取录像状态
    var ret = Live.RecStatus();
    if (1 == ret) {
      alert("Recording!");
      return;
    }
    var RecType = Live.LocalConfigGet(LOCAL_DOWNLOAD_TYPE);
    //开启录像
    ret = Live.RecStart(RecType);	//0:sdv 1:mp4,默认录sdv格式视频
    if (null == ret) {
      alert("RecStart failed!");
    }
  });

  //停止录像
  $('#live_rec_stop').on('click', function () {
    var ret = Live.RecStop();
    if (null == ret) {
      alert("RecStop failed!");
    }
  });

  //打开/关闭声音
  $('#live_volume').on('click', function () {
    //判断有没有class
    if ($(this).hasClass('live_volume')) {
      var openvolume = Live.SpeakerEnable();
      if (null != openvolume) {
        //音量图标置为打开状态
        $(this).removeClass('live_volume');
        //音量条允许滑动
        volume.openChange();
        var rvolume = Live.VolumeGet();
        if ("false" == rvolume) {
          rvolume = 0;
        }
        //设置音量进度条的值
        volume.changewidth(parseInt(rvolume));
        //设置窗口对应静音和声音情况
        var iLength = Live.obsInfos;
        for (var i = 0; i < iLength.length; i++) {
          if (Live.obsInfos[i].obsId == Live.obsId) {
            Live.obsInfos[i].isMute = false;
            Live.obsInfos[i].volume = rvolume;
          }
        }
      }
    } else {
      var closevolume = Live.SpeakerDisable();
      if (null != closevolume) {
        //音量图标置为关闭状态
        $(this).addClass('live_volume');
        //音量条不允许滑动
        volume.stopChange();
        //音量进度条置为0
        volume.changewidth(0);
        //设置窗口对应静音和声音情况
        var iLength = Live.obsInfos;
        for (var i = 0; i < iLength.length; i++) {
          if (Live.obsInfos[i].obsId == Live.obsId) {
            Live.obsInfos[i].isMute = true;
            Live.obsInfos[i].volume = 0;
          }
        }
      }
    }
  });
  function updateLiveValue () {
    var rvolume = volume.getwidth();
    var ret = Live.VolumeSet(parseInt(rvolume));
    var iLength = Live.obsInfos;
    for (var i = 0; i < iLength.length; i++) {
      if (Live.obsInfos[i].obsId == Live.obsId) {
        Live.obsInfos[i].volume = rvolume;
      }
    }
  }
  //设置音量
  $("#live_volume_progress").next().click(function () {
    updateLiveValue();
  }).find('.sliderDot').mouseleave(function () {
    updateLiveValue();
  });

  //PTZ-上
  $("#live_ptz_top").mousedown(function () {
    var channelno = $('#live_channel_list').val();
    var speed = ptzspeed.getwidth();
    var chantype = Live.GetChannelType(parseInt(channelno));
    var ProtocolType = Live.GetDigitalChannelConfig(parseInt(channelno));
    if (null == ProtocolType) {
      Live.PtzControlProtocol(parseInt(channelno), PROTOCOL_MOVE_UP, 0, parseInt(speed), 0);
      return;
    }
    if (0 == parseInt(chantype) || 1 == parseInt(ProtocolType[1])) {
      Live.PtzControlProtocol(parseInt(channelno), PROTOCOL_MOVE_UP, 0, parseInt(speed), 0);
    }
    else if (2 == parseInt(chantype))//数字通道
    {
      Live.PtzControl(parseInt(channelno), TCC_MOVE_UP, parseInt(speed), 0);
    }
    else {
      alert("Not Support Chan Type");
    }
  });
  $("#live_ptz_top").mouseup(function () {
    var channelno = $('#live_channel_list').val();
    var speed = ptzspeed.getwidth();
    var chantype = Live.GetChannelType(parseInt(channelno));
    var ProtocolType = Live.GetDigitalChannelConfig(parseInt(channelno));
    if (null == ProtocolType) {
      Live.PtzControlProtocol(parseInt(channelno), PROTOCOL_MOVE_STOP, 0, parseInt(speed), 0);
      return;
    }
    if (0 == parseInt(chantype) || 1 == parseInt(ProtocolType[1])) {
      Live.PtzControlProtocol(parseInt(channelno), PROTOCOL_MOVE_STOP, 0, parseInt(speed), 0);
    }
    else if (2 == parseInt(chantype)) {
      Live.PtzControl(parseInt(channelno), TCC_MOVE_UP_STOP, 0, 0);
    }
    else {
      alert("Not Support Chan Type");
    }
  });

  //PTZ-下
  $("#live_ptz_down").mousedown(function () {
    var channelno = $('#live_channel_list').val();
    var speed = ptzspeed.getwidth();
    var chantype = Live.GetChannelType(parseInt(channelno));
    var ProtocolType = Live.GetDigitalChannelConfig(parseInt(channelno));
    if (null == ProtocolType) {
      Live.PtzControlProtocol(parseInt(channelno), PROTOCOL_MOVE_DOWN, 0, parseInt(speed), 0);
      return;
    }
    if (0 == parseInt(chantype) || 1 == parseInt(ProtocolType[1])) {
      Live.PtzControlProtocol(parseInt(channelno), PROTOCOL_MOVE_DOWN, 0, parseInt(speed), 0);
    }
    else if (2 == parseInt(chantype)) {
      Live.PtzControl(parseInt(channelno), TCC_MOVE_DOWN, parseInt(speed), 0);
    }
    else {
      alert("Not Support Chan Type");
    }
  });
  $("#live_ptz_down").mouseup(function () {
    var channelno = $('#live_channel_list').val();
    var speed = ptzspeed.getwidth();
    var chantype = Live.GetChannelType(parseInt(channelno));
    var ProtocolType = Live.GetDigitalChannelConfig(parseInt(channelno));
    if (null == ProtocolType) {
      Live.PtzControlProtocol(parseInt(channelno), PROTOCOL_MOVE_STOP, 0, parseInt(speed), 0);
      return;
    }
    if (0 == parseInt(chantype) || 1 == parseInt(ProtocolType[1])) {
      Live.PtzControlProtocol(parseInt(channelno), PROTOCOL_MOVE_STOP, 0, parseInt(speed), 0);
    }
    else if (2 == parseInt(chantype)) {
      Live.PtzControl(parseInt(channelno), TCC_MOVE_DOWN_STOP, 0, 0);
    }
    else {
      alert("Not Support Chan Type");
    }
  });

  //PTZ-左
  $("#live_ptz_left").mousedown(function () {
    var channelno = $('#live_channel_list').val();
    var speed = ptzspeed.getwidth();
    var chantype = Live.GetChannelType(parseInt(channelno));
    var ProtocolType = Live.GetDigitalChannelConfig(parseInt(channelno));
    if (null == ProtocolType) {
      Live.PtzControlProtocol(parseInt(channelno), PROTOCOL_MOVE_LEFT, parseInt(speed), 0, 0);
      return;
    }
    if (0 == parseInt(chantype) || 1 == parseInt(ProtocolType[1])) {
      Live.PtzControlProtocol(parseInt(channelno), PROTOCOL_MOVE_LEFT, parseInt(speed), 0, 0);
    }
    else if (2 == parseInt(chantype)) {
      Live.PtzControl(parseInt(channelno), TCC_MOVE_LEFT, parseInt(speed), 0);
    }
    else {
      alert("Not Support Chan Type");
    }
  });
  $("#live_ptz_left").mouseup(function () {
    var channelno = $('#live_channel_list').val();
    var speed = ptzspeed.getwidth();
    var chantype = Live.GetChannelType(parseInt(channelno));
    var ProtocolType = Live.GetDigitalChannelConfig(parseInt(channelno));
    if (null == ProtocolType) {
      Live.PtzControlProtocol(parseInt(channelno), PROTOCOL_MOVE_STOP, parseInt(speed), 0, 0);
      return;
    }
    if (0 == parseInt(chantype) || 1 == parseInt(ProtocolType[1])) {
      Live.PtzControlProtocol(parseInt(channelno), PROTOCOL_MOVE_STOP, parseInt(speed), 0, 0);
    }
    else if (2 == parseInt(chantype)) {
      Live.PtzControl(parseInt(channelno), TCC_MOVE_LEFT_STOP, 0, 0);
    }
    else {
      alert("Not Support Chan Type");
    }
  });

  //PTZ-右
  $("#live_ptz_right").mousedown(function () {
    var channelno = $('#live_channel_list').val();
    var speed = ptzspeed.getwidth();
    var chantype = Live.GetChannelType(parseInt(channelno));
    var ProtocolType = Live.GetDigitalChannelConfig(parseInt(channelno));
    if (null == ProtocolType) {
      Live.PtzControlProtocol(parseInt(channelno), PROTOCOL_MOVE_RIGHT, parseInt(speed), 0, 0);
      return;
    }
    if (0 == parseInt(chantype) || 1 == parseInt(ProtocolType[1])) {
      Live.PtzControlProtocol(parseInt(channelno), PROTOCOL_MOVE_RIGHT, parseInt(speed), 0, 0);
    }
    else if (2 == parseInt(chantype)) {
      Live.PtzControl(parseInt(channelno), TCC_MOVE_RIGHT, parseInt(speed), 0);
    }
    else {
      alert("Not Support Chan Type");
    }
  });
  $("#live_ptz_right").mouseup(function () {
    var channelno = $('#live_channel_list').val();
    var speed = ptzspeed.getwidth();
    var chantype = Live.GetChannelType(parseInt(channelno));
    var ProtocolType = Live.GetDigitalChannelConfig(parseInt(channelno));
    if (null == ProtocolType) {
      Live.PtzControlProtocol(parseInt(channelno), PROTOCOL_MOVE_STOP, parseInt(speed), 0, 0);
      return;
    }
    if (0 == parseInt(chantype) || 1 == parseInt(ProtocolType[1])) {
      Live.PtzControlProtocol(parseInt(channelno), PROTOCOL_MOVE_STOP, parseInt(speed), 0, 0);
    }
    else if (2 == parseInt(chantype)) {
      Live.PtzControl(parseInt(channelno), TCC_MOVE_RIGHT_STOP, 0, 0);
    }
    else {
      alert("Not Support Chan Type");
    }
  });

  //PTZ-左上
  $("#live_ptz_left_top").mousedown(function () {
    var channelno = $('#live_channel_list').val();
    var speed = ptzspeed.getwidth();
    var chantype = Live.GetChannelType(parseInt(channelno));
    var ProtocolType = Live.GetDigitalChannelConfig(parseInt(channelno));
    if (null == ProtocolType) {
      Live.PtzControlProtocol(parseInt(channelno), PROTOCOL_MOVE_UP_LEFT, parseInt(speed), parseInt(speed), 0);
      return;
    }
    if (0 == parseInt(chantype) || 1 == parseInt(ProtocolType[1])) {
      Live.PtzControlProtocol(parseInt(channelno), PROTOCOL_MOVE_UP_LEFT, parseInt(speed), parseInt(speed), 0);
    }
    else if (2 == parseInt(chantype)) {
      Live.PtzControl(parseInt(channelno), TCC_MOVE_UP_LEFT, parseInt(speed), 0);
    }
    else {
      alert("Not Support Chan Type");
    }
  });
  $("#live_ptz_left_top").mouseup(function () {
    var channelno = $('#live_channel_list').val();
    var speed = ptzspeed.getwidth();
    var chantype = Live.GetChannelType(parseInt(channelno));
    var ProtocolType = Live.GetDigitalChannelConfig(parseInt(channelno));
    if (null == ProtocolType) {
      Live.PtzControlProtocol(parseInt(channelno), PROTOCOL_MOVE_STOP, parseInt(speed), parseInt(speed), 0);
      return;
    }
    if (0 == parseInt(chantype) || 1 == parseInt(ProtocolType[1])) {
      Live.PtzControlProtocol(parseInt(channelno), PROTOCOL_MOVE_STOP, parseInt(speed), parseInt(speed), 0);
    }
    else if (2 == parseInt(chantype)) {
      Live.PtzControl(parseInt(channelno), TCC_MOVE_UP_LEFT_STOP, 0, 0);
    }
    else {
      alert("Not Support Chan Type");
    }
  });

  //PTZ-右上
  $("#live_ptz_right_top").mousedown(function () {
    var channelno = $('#live_channel_list').val();
    var speed = ptzspeed.getwidth();
    var chantype = Live.GetChannelType(parseInt(channelno));
    var ProtocolType = Live.GetDigitalChannelConfig(parseInt(channelno));
    if (null == ProtocolType) {
      Live.PtzControlProtocol(parseInt(channelno), PROTOCOL_MOVE_UP_RIGHT, parseInt(speed), parseInt(speed), 0);
      return;
    }
    if (0 == parseInt(chantype) || 1 == parseInt(ProtocolType[1])) {
      Live.PtzControlProtocol(parseInt(channelno), PROTOCOL_MOVE_UP_RIGHT, parseInt(speed), parseInt(speed), 0);
    }
    else if (2 == parseInt(chantype)) {
      Live.PtzControl(parseInt(channelno), TCC_MOVE_UP_RIGHT, parseInt(speed), 0);
    }
    else {
      alert("Not Support Chan Type");
    }
  });
  $("#live_ptz_right_top").mouseup(function () {
    var channelno = $('#live_channel_list').val();
    var speed = ptzspeed.getwidth();
    var chantype = Live.GetChannelType(parseInt(channelno));
    var ProtocolType = Live.GetDigitalChannelConfig(parseInt(channelno));
    if (null == ProtocolType) {
      Live.PtzControlProtocol(parseInt(channelno), PROTOCOL_MOVE_STOP, parseInt(speed), parseInt(speed), 0);
      return;
    }
    if (0 == parseInt(chantype) || 1 == parseInt(ProtocolType[1])) {
      Live.PtzControlProtocol(parseInt(channelno), PROTOCOL_MOVE_STOP, parseInt(speed), parseInt(speed), 0);
    }
    else if (2 == parseInt(chantype)) {
      Live.PtzControl(parseInt(channelno), TCC_MOVE_UP_RIGHT_STOP, 0, 0);
    }
    else {
      alert("Not Support Chan Type");
    }
  });

  //PTZ-左下
  $("#live_ptz_left_down").mousedown(function () {
    var channelno = $('#live_channel_list').val();
    var speed = ptzspeed.getwidth();
    var chantype = Live.GetChannelType(parseInt(channelno));
    var ProtocolType = Live.GetDigitalChannelConfig(parseInt(channelno));
    if (null == ProtocolType) {
      Live.PtzControlProtocol(parseInt(channelno), PROTOCOL_MOVE_DOWN_LEFT, parseInt(speed), parseInt(speed), 0);
      return;
    }
    if (0 == parseInt(chantype) || 1 == parseInt(ProtocolType[1])) {
      Live.PtzControlProtocol(parseInt(channelno), PROTOCOL_MOVE_DOWN_LEFT, parseInt(speed), parseInt(speed), 0);
    }
    else if (2 == parseInt(chantype)) {
      Live.PtzControl(parseInt(channelno), TCC_MOVE_DOWN_LEFT, parseInt(speed), 0);
    }
    else {
      alert("Not Support Chan Type");
    }
  });
  $("#live_ptz_left_down").mouseup(function () {
    var channelno = $('#live_channel_list').val();
    var speed = ptzspeed.getwidth();
    var chantype = Live.GetChannelType(parseInt(channelno));
    var ProtocolType = Live.GetDigitalChannelConfig(parseInt(channelno));
    if (null == ProtocolType) {
      Live.PtzControlProtocol(parseInt(channelno), PROTOCOL_MOVE_STOP, parseInt(speed), parseInt(speed), 0);
      return;
    }
    if (0 == parseInt(chantype) || 1 == parseInt(ProtocolType[1])) {
      Live.PtzControlProtocol(parseInt(channelno), PROTOCOL_MOVE_STOP, parseInt(speed), parseInt(speed), 0);
    }
    else if (2 == parseInt(chantype)) {
      Live.PtzControl(parseInt(channelno), TCC_MOVE_DOWN_LEFT_STOP, 0, 0);
    }
    else {
      alert("Not Support Chan Type");
    }
  });

  //PTZ-右下
  $("#live_ptz_right_down").mousedown(function () {
    var channelno = $('#live_channel_list').val();
    var speed = ptzspeed.getwidth();
    var chantype = Live.GetChannelType(parseInt(channelno));
    var ProtocolType = Live.GetDigitalChannelConfig(parseInt(channelno));
    if (null == ProtocolType) {
      Live.PtzControlProtocol(parseInt(channelno), PROTOCOL_MOVE_DOWN_RIGHT, parseInt(speed), parseInt(speed), 0);
      return;
    }
    if (0 == parseInt(chantype) || 1 == parseInt(ProtocolType[1])) {
      Live.PtzControlProtocol(parseInt(channelno), PROTOCOL_MOVE_DOWN_RIGHT, parseInt(speed), parseInt(speed), 0);
    }
    else if (2 == parseInt(chantype)) {
      Live.PtzControl(parseInt(channelno), TCC_MOVE_DOWN_RIGHT, parseInt(speed), 0);
    }
    else {
      alert("Not Support Chan Type");
    }
  });
  $("#live_ptz_right_down").mouseup(function () {
    var channelno = $('#live_channel_list').val();
    var speed = ptzspeed.getwidth();
    var chantype = Live.GetChannelType(parseInt(channelno));
    var ProtocolType = Live.GetDigitalChannelConfig(parseInt(channelno));
    if (null == ProtocolType) {
      Live.PtzControlProtocol(parseInt(channelno), PROTOCOL_MOVE_STOP, parseInt(speed), parseInt(speed), 0);
      return;
    }
    if (0 == parseInt(chantype) || 1 == parseInt(ProtocolType[1])) {
      Live.PtzControlProtocol(parseInt(channelno), PROTOCOL_MOVE_STOP, parseInt(speed), parseInt(speed), 0);
    }
    else if (2 == parseInt(chantype)) {
      Live.PtzControl(parseInt(channelno), TCC_MOVE_DOWN_RIGHT_STOP, 0, 0);
    }
    else {
      alert("Not Support Chan Type");
    }
  });

  //PTZ-自动
  $("#live_ptz_auto").mousedown(function () {
    var channelno = $('#live_channel_list').val();
    var speed = ptzspeed.getwidth();
    var chantype = Live.GetChannelType(parseInt(channelno));
    var ProtocolType = Live.GetDigitalChannelConfig(parseInt(channelno));
    if (null == ProtocolType) {
      Live.PtzControlProtocol(parseInt(channelno), SET_HOR_AUTO_BEGIN, 0, 0, 0);
      return;
    }
    if (0 == parseInt(chantype) || 1 == parseInt(ProtocolType[1])) {
      Live.PtzControlProtocol(parseInt(channelno), SET_HOR_AUTO_BEGIN, 0, 0, 0);
    }
    else if (2 == parseInt(chantype)) {
      Live.PtzControl(parseInt(channelno), TCC_HOR_AUTO, parseInt(speed), 0);
    }
    else {
      alert("Not Support Chan Type");
    }
  });

  /*
    $("#live_ptz_auto").mouseup(function(){
      var channelno = $('#live_channel_list').val();
      var speed = ptzspeed.getwidth();
      var chantype = Live.GetChannelType(parseInt(channelno));
      var ProtocolType = Live.GetDigitalChannelConfig(parseInt(channelno));
      if(null == ProtocolType)
      {
        return;
      }
      if(0 == parseInt(chantype) || 1 == parseInt(ProtocolType[1]))
      {
        Live.PtzControlProtocol(parseInt(channelno), SET_HOR_AUTO_BEGIN, 0, 0, 0);
      }
      else if(2 == parseInt(chantype))
      {
        Live.PtzControl(parseInt(channelno),TCC_HOR_AUTO_STOP,0,0);			
      }
      else
      {
        alert("Not Support Chan Type");
      }
    });
  */
  //PTZ-变倍大
  $("#live_ptz_zoom_big").mousedown(function () {
    var channelno = $('#live_channel_list').val();
    var speed = ptzspeed.getwidth();
    var chantype = Live.GetChannelType(parseInt(channelno));
    var ProtocolType = Live.GetDigitalChannelConfig(parseInt(channelno));
    if (null == ProtocolType) {
      Live.PtzControlProtocol(parseInt(channelno), PROTOCOL_ZOOMIN, parseInt(speed), parseInt(speed), 0);
      return;
    }
    if (0 == parseInt(chantype) || 1 == parseInt(ProtocolType[1])) {
      Live.PtzControlProtocol(parseInt(channelno), PROTOCOL_ZOOMIN, parseInt(speed), parseInt(speed), 0);
    }
    else if (2 == parseInt(chantype)) {
      var ret = Live.PtzControl(parseInt(channelno), TCC_ZOOM_BIG, 0, 0);
    }
    else {
      alert("Not Support Chan Type");
    }
  });
  $("#live_ptz_zoom_big").mouseup(function () {
    var channelno = $('#live_channel_list').val();
    var speed = ptzspeed.getwidth();
    var chantype = Live.GetChannelType(parseInt(channelno));
    var ProtocolType = Live.GetDigitalChannelConfig(parseInt(channelno));
    if (null == ProtocolType) {
      Live.PtzControlProtocol(parseInt(channelno), PROTOCOL_MOVE_STOP, parseInt(speed), parseInt(speed), 0);
      return;
    }
    if (0 == parseInt(chantype) || 1 == parseInt(ProtocolType[1])) {
      Live.PtzControlProtocol(parseInt(channelno), PROTOCOL_MOVE_STOP, parseInt(speed), parseInt(speed), 0);
    }
    else if (2 == parseInt(chantype)) {
      Live.PtzControl(parseInt(channelno), TCC_ZOOM_BIG_STOP, 0, 0);
    }
    else {
      alert("Not Support Chan Type");
    }
  });

  //PTZ-变倍小
  $("#live_ptz_zoom_small").mousedown(function () {
    var channelno = $('#live_channel_list').val();
    var speed = ptzspeed.getwidth();
    var chantype = Live.GetChannelType(parseInt(channelno));
    var ProtocolType = Live.GetDigitalChannelConfig(parseInt(channelno));
    if (null == ProtocolType) {
      Live.PtzControlProtocol(parseInt(channelno), PROTOCOL_ZOOMOUT, parseInt(speed), parseInt(speed), 0);
      return;
    }
    if (0 == parseInt(chantype) || 1 == parseInt(ProtocolType[1])) {
      Live.PtzControlProtocol(parseInt(channelno), PROTOCOL_ZOOMOUT, parseInt(speed), parseInt(speed), 0);
    }
    else if (2 == parseInt(chantype)) {
      Live.PtzControl(parseInt(channelno), TCC_ZOOM_SMALL, 0, 0);
    }
    else {
      alert("Not Support Chan Type");
    }
  });
  $("#live_ptz_zoom_small").mouseup(function () {
    var channelno = $('#live_channel_list').val();
    var speed = ptzspeed.getwidth();
    var chantype = Live.GetChannelType(parseInt(channelno));
    var ProtocolType = Live.GetDigitalChannelConfig(parseInt(channelno));
    if (null == ProtocolType) {
      Live.PtzControlProtocol(parseInt(channelno), PROTOCOL_MOVE_STOP, parseInt(speed), parseInt(speed), 0);
      return;
    }
    if (0 == parseInt(chantype) || 1 == parseInt(ProtocolType[1])) {
      Live.PtzControlProtocol(parseInt(channelno), PROTOCOL_MOVE_STOP, parseInt(speed), parseInt(speed), 0);
    }
    else if (2 == parseInt(chantype)) {
      Live.PtzControl(parseInt(channelno), TCC_ZOOM_SMALL_STOP, 0, 0);
    }
    else {
      alert("Not Support Chan Type");
    }
  });

  //PTZ-聚焦远
  $("#live_ptz_focus_far").mousedown(function () {
    var channelno = $('#live_channel_list').val();
    var speed = ptzspeed.getwidth();
    var chantype = Live.GetChannelType(parseInt(channelno));
    var ProtocolType = Live.GetDigitalChannelConfig(parseInt(channelno));
    if (null == ProtocolType) {
      Live.PtzControlProtocol(parseInt(channelno), PROTOCOL_FOCUS_OFF, parseInt(speed), parseInt(speed), 0);
      return;
    }
    if (0 == parseInt(chantype) || 1 == parseInt(ProtocolType[1])) {
      Live.PtzControlProtocol(parseInt(channelno), PROTOCOL_FOCUS_OFF, parseInt(speed), parseInt(speed), 0);
    }
    else if (2 == parseInt(chantype)) {
      Live.PtzControl(parseInt(channelno), TCC_FOCUS_FAR, 0, 0);
    }
    else {
      alert("Not Support Chan Type");
    }
  });
  $("#live_ptz_focus_far").mouseup(function () {
    var channelno = $('#live_channel_list').val();
    var speed = ptzspeed.getwidth();
    var chantype = Live.GetChannelType(parseInt(channelno));
    var ProtocolType = Live.GetDigitalChannelConfig(parseInt(channelno));
    if (null == ProtocolType) {
      Live.PtzControlProtocol(parseInt(channelno), PROTOCOL_MOVE_STOP, parseInt(speed), parseInt(speed), 0);
      return;
    }
    if (0 == parseInt(chantype) || 1 == parseInt(ProtocolType[1])) {
      Live.PtzControlProtocol(parseInt(channelno), PROTOCOL_MOVE_STOP, parseInt(speed), parseInt(speed), 0);
    }
    else if (2 == parseInt(chantype)) {
      Live.PtzControl(parseInt(channelno), TCC_FOCUS_FAR_STOP, 0, 0);
    }
    else {
      alert("Not Support Chan Type");
    }
  });

  //PTZ-聚焦近
  $("#live_ptz_focus_near").mousedown(function () {
    var channelno = $('#live_channel_list').val();
    var speed = ptzspeed.getwidth();
    var chantype = Live.GetChannelType(parseInt(channelno));
    var ProtocolType = Live.GetDigitalChannelConfig(parseInt(channelno));
    if (null == ProtocolType) {
      Live.PtzControlProtocol(parseInt(channelno), PROTOCOL_FOCUS_ON, parseInt(speed), parseInt(speed), 0);
      return;
    }
    if (0 == parseInt(chantype) || 1 == parseInt(ProtocolType[1])) {
      Live.PtzControlProtocol(parseInt(channelno), PROTOCOL_FOCUS_ON, parseInt(speed), parseInt(speed), 0);
    }
    else if (2 == parseInt(chantype)) {
      Live.PtzControl(parseInt(channelno), TCC_FOCUS_NEAR, 0, 0);
    }
    else {
      alert("Not Support Chan Type");
    }
  });
  $("#live_ptz_focus_near").mouseup(function () {
    var channelno = $('#live_channel_list').val();
    var speed = ptzspeed.getwidth();
    var chantype = Live.GetChannelType(parseInt(channelno));
    var ProtocolType = Live.GetDigitalChannelConfig(parseInt(channelno));
    if (null == ProtocolType) {
      Live.PtzControlProtocol(parseInt(channelno), PROTOCOL_MOVE_STOP, parseInt(speed), parseInt(speed), 0);
      return;
    }
    if (0 == parseInt(chantype) || 1 == parseInt(ProtocolType[1])) {
      Live.PtzControlProtocol(parseInt(channelno), PROTOCOL_MOVE_STOP, parseInt(speed), parseInt(speed), 0);
    }
    else if (2 == parseInt(chantype)) {
      Live.PtzControl(parseInt(channelno), TCC_FOCUS_NEAR_STOP, 0, 0);
    }
    else {
      alert("Not Support Chan Type");
    }
  });

  //PTZ-光圈增大
  $("#live_ptz_iris_open").mousedown(function () {
    var channelno = $('#live_channel_list').val();
    var speed = ptzspeed.getwidth();
    var chantype = Live.GetChannelType(parseInt(channelno));
    var ProtocolType = Live.GetDigitalChannelConfig(parseInt(channelno));
    if (null == ProtocolType) {
      Live.PtzControlProtocol(parseInt(channelno), PROTOCOL_IRIS_OPEN, parseInt(speed), parseInt(speed), 0);
      return;
    }
    if (0 == parseInt(chantype) || 1 == parseInt(ProtocolType[1])) {
      Live.PtzControlProtocol(parseInt(channelno), PROTOCOL_IRIS_OPEN, parseInt(speed), parseInt(speed), 0);
    }
    else if (2 == parseInt(chantype)) {
      Live.PtzControl(parseInt(channelno), TCC_IRIS_OPEN, 0, 0);
    }
    else {
      alert("Not Support Chan Type");
    }
  });
  $("#live_ptz_iris_open").mouseup(function () {
    var channelno = $('#live_channel_list').val();
    var speed = ptzspeed.getwidth();
    var chantype = Live.GetChannelType(parseInt(channelno));
    var ProtocolType = Live.GetDigitalChannelConfig(parseInt(channelno));
    if (null == ProtocolType) {
      Live.PtzControlProtocol(parseInt(channelno), PROTOCOL_MOVE_STOP, parseInt(speed), parseInt(speed), 0);
      return;
    }
    if (0 == parseInt(chantype) || 1 == parseInt(ProtocolType[1])) {
      Live.PtzControlProtocol(parseInt(channelno), PROTOCOL_MOVE_STOP, parseInt(speed), parseInt(speed), 0);
    }
    else if (2 == parseInt(chantype)) {
      Live.PtzControl(parseInt(channelno), TCC_IRIS_OPEN_STOP, 0, 0);
    }
    else {
      alert("Not Support Chan Type");
    }
  });

  //PTZ-光圈减小
  $("#live_ptz_iris_close").mousedown(function () {
    var channelno = $('#live_channel_list').val();
    var speed = ptzspeed.getwidth();
    var chantype = Live.GetChannelType(parseInt(channelno));
    var ProtocolType = Live.GetDigitalChannelConfig(parseInt(channelno));
    if (null == ProtocolType) {
      Live.PtzControlProtocol(parseInt(channelno), PROTOCOL_IRIS_CLOSE, parseInt(speed), parseInt(speed), 0);
      return;
    }
    if (0 == parseInt(chantype) || 1 == parseInt(ProtocolType[1])) {
      Live.PtzControlProtocol(parseInt(channelno), PROTOCOL_IRIS_CLOSE, parseInt(speed), parseInt(speed), 0);
    }
    else if (2 == parseInt(chantype)) {
      Live.PtzControl(parseInt(channelno), TCC_IRIS_CLOSE, 0, 0);
    }
    else {
      alert("Not Support Chan Type");
    }
  });
  $("#live_ptz_iris_close").mouseup(function () {
    var channelno = $('#live_channel_list').val();
    var speed = ptzspeed.getwidth();
    var chantype = Live.GetChannelType(parseInt(channelno));
    var ProtocolType = Live.GetDigitalChannelConfig(parseInt(channelno));
    if (null == ProtocolType) {
      Live.PtzControlProtocol(parseInt(channelno), PROTOCOL_MOVE_STOP, parseInt(speed), parseInt(speed), 0);
      return;
    }
    if (0 == parseInt(chantype) || 1 == parseInt(ProtocolType[1])) {
      Live.PtzControlProtocol(parseInt(channelno), PROTOCOL_MOVE_STOP, parseInt(speed), parseInt(speed), 0);
    }
    else if (2 == parseInt(chantype)) {
      Live.PtzControl(parseInt(channelno), TCC_IRIS_CLOSE_STOP, 0, 0);
    }
    else {
      alert("Not Support Chan Type");
    }
  });

  //PTZ-控制速度
  $("#live_ptz_speed").next().click(function () {
    var progress = ptzspeed.getwidth();
    //设置ptz控制数值
    $('#live_ptz_value').html(progress);
  }).find('.sliderDot').mouseleave(function () {
    var progress = ptzspeed.getwidth();
    //设置ptz控制数值
    $('#live_ptz_value').html(progress);
  });

  //PTZ-预置位设置
  $('#live_ptz_preset_set').on('click', function () {
    var channelno = $('#live_channel_list').val();
    var speed = ptzspeed.getwidth();
    //获取预置位编号
    var presetNo = $("#live_ptz_preset_list").val();
    var chantype = Live.GetChannelType(parseInt(channelno));
    var ProtocolType = Live.GetDigitalChannelConfig(parseInt(channelno));
    if (null == ProtocolType) {
      Live.PtzControlProtocol(parseInt(channelno), PROTOCOL_DELETE_PRESET, parseInt(presetNo), parseInt(speed), 0);
      var ret = Live.PtzControlProtocol(parseInt(channelno), PROTOCOL_SET_PRESET, parseInt(presetNo), parseInt(speed), 0);
      if (null == ret) {
        alert("PresetAdd failed!");
      }
      return;
    }
    if (0 == parseInt(chantype) || 1 == parseInt(ProtocolType[1])) {
      Live.PtzControlProtocol(parseInt(channelno), PROTOCOL_DELETE_PRESET, parseInt(presetNo), parseInt(speed), 0);
      var ret = Live.PtzControlProtocol(parseInt(channelno), PROTOCOL_SET_PRESET, parseInt(presetNo), parseInt(speed), 0);
      if (null == ret) {
        alert("PresetAdd failed!");
      }
    }
    else if (2 == parseInt(chantype)) {
      //先删除预置位
      var ret = Live.PresetDelete(parseInt(channelno), parseInt(presetNo));
      //添加预置位
      var ret = Live.PresetAdd(parseInt(channelno), parseInt(presetNo));
      if (null == ret) {
        alert("PresetAdd failed!");
      }
    }
    else {
      alert("Not Support Chan Type");
    }
  });

  //PTZ-预置位调用
  $('#live_ptz_preset_call').on('click', function () {
    var channelno = $('#live_channel_list').val();
    //获取预置位编号
    var presetNo = $("#live_ptz_preset_list").val();
    var speed = ptzspeed.getwidth();
    var chantype = Live.GetChannelType(parseInt(channelno));
    var ProtocolType = Live.GetDigitalChannelConfig(parseInt(channelno));
    if (null == ProtocolType) {
      var ret = Live.PtzControlProtocol(parseInt(channelno), PROTOCOL_PRESET, parseInt(presetNo), parseInt(speed), 0);
      if (null == ret) {
        alert("PresetCall failed!");
      }
      return;
    }
    if (0 == parseInt(chantype) || 1 == parseInt(ProtocolType[1])) {
      var ret = Live.PtzControlProtocol(parseInt(channelno), PROTOCOL_PRESET, parseInt(presetNo), parseInt(speed), 0);
      if (null == ret) {
        alert("PresetCall failed!");
      }
    }
    else if (2 == parseInt(chantype)) {
      var ret = Live.PresetCall(parseInt(channelno), parseInt(presetNo));
      if (null == ret) {
        alert("PresetCall failed!");
      }
    }
    else {
      alert("Not Support Chan Type");
    }
  });


  // --------------------------回放界面命令码方法
  //抓拍图片
  $('#back_snap').on('click', function () {
    var SnapType = Playback.LocalConfigGet(LOCAL_CAPTURE_TYPE);
    var ret = Playback.SnapShot(SnapType); //1:bmp 2:jpg
    if (null == ret) {
      alert("SnapShort failed!");
    }

  });
  //回放-播放
  $('#back_play').on('click', function () {
    var ret = Playback.Resume();
    if (null == ret) {
      alert("Play failed!");
    }
  });

  //回放-暂停
  $('#back_pause').on('click', function () {
    var ret = Playback.Pause();
    if (null == ret) {
      alert("Pause failed!");
    }
  });

  //回放-停止
  $('#back_stop').on('click', function () {
    var ret = Playback.Stop();
    if (null == ret) {
      alert("Stop failed!");
    }
  });

  //回放-快进
  $('#back_fast').on('click', function () {
    var ret = Playback.FastForword(4);
    if (null == ret) {
      alert("FastForword failed!");
    }
  });

  //回放-慢进
  $('#back_slow').on('click', function () {
    var ret = Playback.SlowForward(4);
    if (null == ret) {
      alert("SlowForward failed!");
    }
  });

  //回放-单帧步进
  $('#back_step').on('click', function () {
    var ret = Playback.StepForward();
    if (null == ret) {
      alert("StepForward failed!");
    }
  });

  //回放-本地文件
  $('#back_localfile').on('click', function () {
    var filePath = Live.LocalConfigGet(0);	//获取本地配置中录像存储路径
    var ret = Playback.OpenFile(filePath);
    if (null == ret) {
      //alert("Open Local File failed!");
    }
    else {
      PlayBackType = 0;
      totalTime = Playback.GetTotalTime();
      totalTime = senctotime(parseInt(totalTime));
      if (null == interval) {
        interval = setInterval(clock, 500);
      }
      CloseBackvolume();
    }
  });

  //回放-录像查询
  $('#back_recfile_query').on('click', function () {
    totalPage = 0;
    currentPage = 0;
    QureyFile(1);	//查询是默认查第一页
  });

  //回放-录像首页
  $('#back_page_first').on('click', function () {
    QureyFile(1);
  });

  //回放-录像上一页
  $('#back_page_pre').on('click', function () {
    var pageNo = currentPage - 1;
    if (pageNo <= 0) {
      return;
    }
    QureyFile(pageNo);
  });

  //回放-录像下一页
  $('#back_page_next').on('click', function () {
    var pageNo = currentPage + 1;
    if (pageNo > totalPage) {
      return;
    }
    QureyFile(pageNo);
  });

  //回放-录像尾页
  $('#back_page_last').on('click', function () {
    if (totalPage > 0) {
      QureyFile(totalPage);
    }
  });

  //回放-按页码号查询文件
  function QureyFile (pageNo) {
    //参数校验
    if (pageNo < 1 || (pageNo > totalPage && totalPage > 0)) {
      return;
    }

    //$('#back_table_recfile').empty();
    $('#back_page_size').text("0/0");

    //先停止下载
    Playback.StopDownload();

    //查询
    var channelNo = $('#back_channel_list').val();		//通道号
    var startTime = $('#back_start_time').val();		//开始时间
    startTime = moment(startTime).format('YYYYMMDDHHmmss');
    var stopTime = $('#back_stop_time').val();			//结束时间
    stopTime = moment(stopTime).format('YYYYMMDDHHmmss');
    var recType = 0xFF;									//0xFF-All, 1-手动, 2-定时, 3-报警
    var pageCount = 20;									//每页最大文件个数
    var ret = Playback.Query(startTime, stopTime, channelNo, recType, pageNo, pageCount);
    if (0 != ret[0]) {
      alert("Query Record File failed!");
      return;
    }
    //先清空表格中内容
    var tabObj = document.getElementById("back_table_recfile");
    var rows = tabObj.rows;
    if (tabObj.rows.length > 1) {
      for (var i = tabObj.rows.length; i > 1; i--) {
        tabObj.deleteRow(i - 1);
      }
    }
    //录像文件总个数
    var totalCount = parseInt(ret[1]);
    if (totalCount <= 0 || isNaN(totalCount)) {
      return;
    }
    //总页数
    totalPage = parseInt(totalCount / pageCount);
    if (0 != totalCount % pageCount) {
      totalPage += 1;
    }

    //保存当前页码
    if (currentPage <= totalPage) {
      currentPage = pageNo;
    }

    //显示总页数和当前页码	
    $('#back_page_size').text(currentPage + "/" + totalPage);

    var dom;
    var data = $.parseJSON(ret[2]).param;
    data.forEach(function (item) {
      dom = [
        '<tr>',
        '<td class = "back_file_name">' + item.filename + '</td>',
        '<td>' + item.starttime + '</td>',
        '<td>' + item.endtime + '</td>',
        '<td>',
        '<a style= "cursor:pointer" class = "back_file_play">Play</a>',
        '</td>',
        '<td style = "text-align: center;">',
        '<a style= "cursor:pointer" class = "back_file_download">Download</a>',
        '</td>',
        '<td style = "text-align: center;">',
        '<a style= "cursor:pointer" class = "back_file_Stopdownload">StopDownload</a>',
        '</td>',
        '<td class = "back_download_state" style = "text-align: center;"></td>',
        '</tr>'
      ].join('');
      $('#back_table_recfile').append(dom)
    })
  };

  //关闭回放音量函数
  function CloseBackvolume () {
    backvolume.changewidth(0);
    //音量图标置为关闭状态
    $('#back_volume').addClass('live_volume');
    //音量条不允许滑动
    backvolume.stopChange();
  };
  //回放-按时间段回放
  $('#back_play_by_time').on('click', function () {
    var channelNo = $('#back_channel_list').val();		//通道号
    var startTime = $('#back_start_time').val();		//开始时间
    var startTime = moment(startTime).format('YYYYMMDDHHmmss');
    var backstopTime = $('#back_stop_time').val();			//结束时间
    var stopTime = moment(backstopTime).format('YYYYMMDDHHmmss');
    var ret = Playback.PlayBackByTime(startTime, stopTime, channelNo);
    if (null == ret) {
      alert("PlayBackByTime failed!");
    } else {
      PlayBackType = 1;
      totalTime = backstopTime;
      if (null == interval) {
        interval = setInterval(clock, 500);
      }
      CloseBackvolume();
    }
  });

  //回放-按时间段下载
  $('#back_download_bytime').on('click', function () {
    var channelNo = $('#back_channel_list').val();		//通道号
    var backstartTime = $('#back_start_time').val();		//开始时间
    var startTime = moment(backstartTime).format('YYYYMMDDHHmmss');
    var backstopTime = $('#back_stop_time').val();			//结束时间
    var stopTime = moment(backstopTime).format('YYYYMMDDHHmmss');
    var localFileName = startTime + '_' + stopTime;
    //判断是下载mp4还是sdv文件
    var RecType = Live.LocalConfigGet(LOCAL_DOWNLOAD_TYPE);//0:sdv 1:mp4,默认录sdv格式视频
    if (1 == RecType) {
      localFileName = localFileName + ".mp4";
    }
    else {
      localFileName = localFileName + ".sdv";
    }
    //保存全路径
    var downloadPath = Playback.LocalConfigGet(LOCAL_DNL_FILE_PATH);
    downloadPath += localFileName;

    var ret = Playback.DownloadByTime(downloadPath, parseInt(channelNo), 0, startTime, stopTime, RecType);
    if (null == ret) {
      alert("PlayBackByTime failed!");
    } else {
      //获取下载进度
      result = $("#back_download_bytime_progress");
      //vy.value = result;
      downloadProgress = setInterval(getProgress, 500);
      downloadstate = -1;
    }
  });
  //停止下载
  $('#back_download_bytime_stop').on('click', function () {
    downloadstate = -1;
    clearInterval(downloadProgress);
    Playback.StopDownload();
  });
  //回放-远程按文件播放
  $('table').on('click', '.back_file_play', function () {
    var fileName = $(this).parent('td').siblings('.back_file_name').text();
    var ret = Playback.PlayBackByFileName(fileName);
    if (null == ret) {
      alert("PlayBackByFileName failed!");
    } else {
      PlayBackType = 0;
      totalTime = Playback.GetTotalTime();
      totalTime = senctotime(parseInt(totalTime));
      if (null == interval) {
        interval = setInterval(clock, 500);
      }
      CloseBackvolume();
    }
  });

  // 获取前端录像文件下载进度
  function getProgress () {
    if (0 == downloadstate) {
      $(result).text(100 + '%');
      clearInterval(downloadProgress);
      Playback.StopDownload();
    }
    else {
      var count = Playback.GetDownloadProgress();
      if (count === 100 || typeof count === 'undefined' || count < 0) {
        $(result).text('Download Failed');
        clearInterval(downloadProgress)
        if (count === 100) {
          downloadstate = 0;
          $(result).text('Download Success')
        }
        //停止下载
        Playback.StopDownload();
        return;
      } else {
        $(result).text(count + '%');
      }
    }
  }



  //回放-远程文件下载
  $('table').on('click', '.back_file_download', function () {
    //下载录像文件名称
    var remotefileName = $(this).parent('td').siblings('.back_file_name').text();
    var localFileName = remotefileName;
    //判断是下载mp4还是sdv文件
    var RecType = Live.LocalConfigGet(LOCAL_DOWNLOAD_TYPE);//0:sdv 1:mp4,默认录sdv格式视频
    if (1 == RecType) {
      localFileName = remotefileName.split('.');
      localFileName = localFileName[0] + ".mp4";
    }
    //保存全路径
    var downloadPath = Playback.LocalConfigGet(LOCAL_DNL_FILE_PATH);
    downloadPath += localFileName;

    //开始下载
    var downloadId = Playback.Download(remotefileName, downloadPath, parseInt(RecType));
    if (null == downloadId) {
      alert("Download failed!");
      return;
    } else if (-1 == downloadId) {
      alert("Downloading, Please Stop First!");
      return;
    }

    //获取下载进度
    result = $(this).parent('td').siblings('.back_download_state');
    downloadProgress = setInterval(getProgress, 500);
    downloadstate = -1;
  });

  //回放-远程文件停止下载
  $('table').on('click', '.back_file_Stopdownload', function () {
    downloadstate = -1;
    clearInterval(downloadProgress);
    Playback.StopDownload();
  });
  //时间转换函数
  function senctotime (v1) {
    var hourTime = "0";
    var minuteTime = "0";
    var secondTime = "0";
    if (v1 >= 60) {
      minuteTime = parseInt(v1 / 60);
      secondTime = parseInt(v1 % 60);
      if (minuteTime > 60) {
        hourTime = parseInt(minuteTime / 60);
        minuteTime = parseInt(minuteTime % 60);
      }
    }
    else {
      secondTime = v1;
    }
    parseInt(hourTime) < 10 ? hourTime = "0" + hourTime : hourTime = hourTime;
    parseInt(minuteTime) < 10 ? minuteTime = "0" + minuteTime : minuteTime = minuteTime;
    parseInt(secondTime) < 10 ? secondTime = "0" + secondTime : secondTime = secondTime;
    v1 = hourTime + '' + ':' + minuteTime + '' + ':' + secondTime;
    return v1;
  }

  //定时器函数
  function clock () {
    var realTime = Playback.GetNowTime();
    if (0 == PlayBackType) {
      realTime = senctotime(parseInt(realTime));
    } else {
      realTime = moment(realTime * 1000).format('YYYY-MM-DD HH:mm:ss');
    }
    var value = realTime + ' ' + '/' + ' ' + totalTime;
    $('#back_time').html(value);
    var backstate = Playback.GetPlaybackState();
    if (parseInt(backstate) == 0) {
      clearInterval(interval);
      interval = null;
      value = "00:00:00/00:00:00";
      $('#back_time').html(value);
      CloseBackvolume();
    }
  }

  //回放-定位
  // $("#back_progress").next().find('.sliderDot').mouseleave(function(){
  // 	var progress = backprogress.getwidth();
  // 	var	ret = Playback.SetPlayBackProgress(parseInt(progress));
  // });

  //打开/关闭声音
  $('#back_volume').on('click', function () {
    //判断有没有class
    if ($(this).hasClass('live_volume')) {
      var openvolume = Playback.SpeakerEnable();
      if (null != openvolume) {
        //音量图标置为打开状态
        $(this).removeClass('live_volume');
        //音量条允许滑动
        backvolume.openChange();
        var rvolume = Playback.VolumeGet();
        //获取失败，音量数值为0
        if ("false" == rvolume) {
          rvolume = 0;
        }
        //改变音量进度条
        backvolume.changewidth(parseInt(rvolume));
      }
    } else {
      var closevolume = Playback.SpeakerDisable();
      if (null != closevolume) {
        CloseBackvolume();
      }
    }
  });
  //回放-录像声音
  $("#back_volume_progress").next().click(function () {
    var rvolume = backvolume.getwidth();
    var ret = Playback.VolumeSet(parseInt(rvolume));
  }).find('.sliderDot').mouseleave(function () {
    var rvolume = backvolume.getwidth();
    var ret = Playback.VolumeSet(parseInt(rvolume));
  });


  // --------------------------配置界面命令码方法

  $('.cfgeditbtn').on('click', function () {
    var $e = $(this);
    var edit = $e.parent().parent().find('input');
    var s = Live.BrowseFolder(edit.val());
    if (s != null)
      edit.val(s);
  });
  //................表格換頁
  $('#page_first').on('click', function () {
    var page = $('#page_size').text();
    $('#page_size').text('1/10');
    //todo 查找第一页并显示
  });
  //...............
  // 设置存储信息
  $('#filelocation_save').click(function () {
    $('#filelocation').find("input[data-k],select[data-k]").each(function () {
      var v1 = $(this).data("k");
      var type = $(this).data("t");
      var v2 = '';
      switch (type) {
        case 1:
          v2 = $(this).prop('checked') ? 1 : 0;
          break;
        case 2:
          v2 = $(this).val();
          break;
        case 3:
          v2 = parseFloat($(this).val());
          break;
      }
      Live.LocalConfigSet(v1, v2);
    })
  });
  //获取存储信息
  $('#filelocation_fresh').on('click', function () {
    // 获得存储地址赋值
    $('#filelocation').find("input[data-k],select[data-k]").each(function () {
      var v1 = $(this).data("k");
      var type = $(this).data("t");
      var m = '';
      switch (type) {
        case 1:
          m = Live.LocalConfigGet(v1);
          if (m == 1) {
            $(this).prop('checked', true);
          } else {
            $(this).prop('checked', false);
          }
          break;
        case 2:
          m = Live.LocalConfigGet(v1);
          $(this).val(m);
          break;
        case 3:
          m = Live.LocalConfigGet(v1);
          $(this).find("option[value='" + m + "']").prop("selected", "selected");
          break;
      }
    })
  });

  //视频基本参数界面播放视频
  $('#cfg_basic_startplay').on('click', function () {
    //先停止之前的播放
    Cfgbasic.Stop();
    var chanNo = $("#cfg_basic_channelno").val();	//通道号
    var streamNo = $("#cfg_basic_streamtype").val();
    var ret = Cfgbasic.Play(chanNo, streamNo);
    if (null == ret) {
      alert("play failed!");
    }
  });
  //视频基本参数界面停止播放视频
  $('#cfg_basic_stopplay').on('click', function () {
    Cfgbasic.Stop();
  });

  //设置视频基本参数
  $('#cfg_basic_set').on('click', function () {
    if (3 != Cfgbasic.iLogonState) {
      alert("Not Login");
      return;
    }
    var vchannum = $("#cfg_basic_channelno").val();
    var vstreamtype = $("#cfg_basic_streamtype").val();
    var vvideosize, vbyterate, vframerate, viframerate, vvenctype;
    $('#cfgbasic').find("select[data-k]").each(function () {
      var vtmp = $(this).data("k");
      switch (vtmp) {
        case 1:
          vvideosize = $(this).val();
          break;
        case 2:
          vbyterate = $(this).val();
          break;
        case 3:
          vframerate = $(this).val();
          break;
        case 4:
          viframerate = $(this).val();
          break;
        case 5:
          vvenctype = $(this).val();
          break;
      }
    })
    Cfgbasic.SetVideoSize(parseInt(vchannum), parseInt(vstreamtype), parseInt(vvideosize));
    Cfgbasic.SetVideoByteRate(parseInt(vchannum), parseInt(vstreamtype), parseInt(vbyterate));
    Cfgbasic.SetVideoFrameRate(parseInt(vchannum), parseInt(vstreamtype), parseInt(vframerate));
    Cfgbasic.SetVideoIFrameRate(parseInt(vchannum), parseInt(vstreamtype), parseInt(viframerate));
    Cfgbasic.SetVideoVencType(parseInt(vchannum), parseInt(vstreamtype), parseInt(vvenctype));
  });

  //配置界面点击响应函数
  $('#configuration_id').on('click', function () {
    if (3 != Cfgbasic.iLogonState) {
      alert("Please Login");
      return;
    }
    $('#cfg_basic_refresh').trigger('click');
  });

  //basic_set界面点击响应函数
  $('#basic_set_id').on('click', function () {
    if (3 != Cfgbasic.iLogonState) {
      return;
    }
    $('#cfg_basic_refresh').trigger('click');
  });

  //manage_channel界面点击响应函数
  $('#manage_channel_id').on('click', function () {
    if (3 != Live.iLogonState) {
      return;
    }
    $('#cfg_manager_chantype_refresh').trigger('click');
    $('#cfg_manager_dig_refresh').trigger('click');
  });

  //osd_set界面点击响应函数
  $('#osd_set_id').on('click', function () {
    if (3 != Cfgosd.iLogonState) {
      return;
    }
    $('#cfg_osd_title_refresh').trigger('click');
    $('#cfg_osd_date_refresh').trigger('click');
    $('#cfg_osd_addition_refresh').trigger('click');
  });

  //local_set界面点击响应函数
  $('#local_set_id').on('click', function () {
    if (3 != Cfgosd.iLogonState) {
      return;
    }
    $('#filelocation_fresh').trigger('click');
  });

  //System Set Page Respond Function
  $('#system_set_id').on('click', function () {
    //get factory id
    var ret1 = Live.GetFactoryID();
    if (null != ret1) {
      var factoryid = document.getElementById("system_set_factory_id");
      factoryid.value = ret1[0];
    }
    var ret2 = Live.GetVersionInfo();
    if (null != ret2) {
      var firmware = document.getElementById("system_set_firmware_version");
      firmware.value = ret2[4];

      var encoder = document.getElementById("system_set_encoder_version");
      encoder.value = ret2[2];
    }

    var ret3 = Live.GetNVSAddr();
    if (null != ret3) {
      var mac = document.getElementById("system_set_mac");
      mac.value = ret3[2];
    }

    var chanNo = -1;
    var devtype = $('#system_dev_ipc_nvr').val();
    if (2 == parseInt(devtype)) {
      chanNo = 0x7fffffff;
    }
    else {
      chanNo = $("#live_channel_list").val();	//Channel number
    }

    //var ret4 = Live.GetDevName(parseInt(chanNo));
    //if(null != ret4)
    //{
    //var devicename = document.getElementById("system_set_device_name");
    //devicename.value = ret4[0];
    //}

    //chanNo = $("#live_channel_list").val();	//Channel number
    //var ret5 = Live.GetDevMode(parseInt(chanNo));
    //if(null != ret5)
    //{
    //var devicemode = document.getElementById("system_set_device_type");
    //devicemode.value = ret5[0];
    //}
  });

  //获取视频基本参数
  $('#cfg_basic_refresh').on('click', function () {
    if (3 != Cfgbasic.iLogonState) {
      return;
    }
    var v1 = $('#cfg_basic_channelno').val();
    $('#cfg_basic_channelno').find("option[value='" + v1 + "']").prop("selected", "selected");
    var v2 = $('#cfg_basic_streamtype').val();
    $('#cfg_basic_streamtype').find("option[value='" + v2 + "']").prop("selected", "selected");
    var videosizelist = Cfgbasic.GetVideoSizeList(parseInt(v1), parseInt(v2));
    var videosize = Cfgbasic.GetVideoSize(parseInt(v1), parseInt(v2));
    var bitrate = Cfgbasic.GetVideoByteRate(parseInt(v1), parseInt(v2));
    var rframelist = Cfgbasic.GetVideoFrameList(parseInt(v1), parseInt(v2));
    var framerate = Cfgbasic.GetVideoFrameRate(parseInt(v1), parseInt(v2));
    var iframerate = Cfgbasic.GetVideoIFrameRate(parseInt(v1), parseInt(v2));
    var enclist = Cfgbasic.GetVideoEncodeList(parseInt(v1), parseInt(v2));
    var enc = Cfgbasic.GetVideoVencType(parseInt(v1), parseInt(v2));
    $('#cfgbasic').find("select[data-k]").each(function () {
      var vtmp = $(this).data("k");
      switch (vtmp) {
        case 1:
          var q = '';
          for (var i = 0; i < videosizelist.length; i++) {
            if (videosize == videosizelist[i]) {
              if (g_mapPVSize.has(parseInt(videosize))) {
                q += '<option value=' + parseInt(videosize) + ' selected >' + g_mapPVSize.get(parseInt(videosize)) + '</option>';//怎么对应分辨率的val
              }
            } else {
              if (g_mapPVSize.has(parseInt(videosizelist[i]))) {
                q += '<option value=' + parseInt(videosizelist[i]) + '>' + g_mapPVSize.get(parseInt(videosizelist[i])) + '</option>';
              }
            }
          }
          $(this).html(q);
          break;
        case 2:
          $(this).find("option[value='" + bitrate * 8 + "']").prop("selected", "selected");
          break;
        case 3:
          var q = '';
          for (var rcount = rframelist.length - 1; rcount >= 0; rcount--) {
            q += '<option value=' + rframelist[rcount] + '>' + rframelist[rcount] + '</option>'
          }
          $(this).html(q);
          $(this).find("option[value='" + framerate + "']").prop("selected", "selected");
          break;
        case 4:
          $(this).find("option[value='" + iframerate + "']").prop("selected", "selected");
          break;
        case 5:
          var q = '';
          if (enclist & 0x01) {
            if (H264B == enc) {
              q += '<option value="' + H264B + '" selected >' + 'H.264B' + '</option>'
            } else {
              q += '<option value="' + H264B + '">' + 'H.264B' + '</option>'
            }
            if (H264M == enc) {
              q += '<option value="' + H264M + '" selected >' + 'H.264M' + '</option>'
            } else {
              q += '<option value="' + H264M + '">' + 'H.264M' + '</option>'
            }
            if (H264H == enc) {
              q += '<option value="' + H264H + '" selected >' + 'H.264H' + '</option>'
            } else {
              q += '<option value="' + H264H + '">' + 'H.264H' + '</option>'
            }
          }
          if (enclist & 0x01 << 1) {
            if (MJPEG == enc) {
              q += '<option value="' + MJPEG + '" selected>' + 'M-JPEG' + '</option>'
            } else {
              q += '<option value="' + MJPEG + '">' + 'M-JPEG' + '</option>'
            }
          }
          if (enclist & 0x01 << 2) {
            if (MPEG4 == enc) {
              q += '<option value="' + MPEG4 + '" selected >' + 'MPEG4' + '</option>'
            } else {
              q += '<option value="' + MPEG4 + '">' + 'MPEG4' + '</option>'
            }
          }
          if (enclist & 0x01 << 3) {
            if (H265 == enc) {
              q += '<option value="' + H265 + '" selected >' + 'H.265' + '</option>'
            } else {
              q += '<option value="' + H265 + '">' + 'H.265' + '</option>'
            }
          }
          $(this).html(q);
          break;
      }
    })
  });

  //设置通道类型
  $('#cfg_manager_chantype_set').on('click', function () {
    if (3 != Live.iLogonState) {
      return;
    }
    var vchannum = $('#cfg_manager_chan').val();
    var vchantype = $('#cfg_manager_chantype').val();
    if (3 == parseInt(vchantype)) {
      alert("Not Support Set Composite Channel");
      return;
    }
    Live.SetChannelType(parseInt(vchannum), parseInt(vchantype));
    alert("Restart effective");
  });
  //获取通道类型
  $('#cfg_manager_chantype_refresh').on('click', function () {
    if (3 != Live.iLogonState) {
      return;
    }
    var vchannum = $('#cfg_manager_chan').val();
    var r = Live.GetChannelType(parseInt(vchannum));
    if (null == r) {
      return;
    }
    $('#cfg_manager_chantype').find("option[value='" + r + "']").prop("selected", "selected");
  });

  //设置数字通道
  $('#cfg_manager_dig_set').on('click', function () {
    if (3 != Live.iLogonState) {
      return;
    }
    var vchannum = $('#cfg_manager_chan').val();
    var vdevicetype = $('#cfg_manager_dig_devicetype').val();
    var vip = document.getElementById("cfg_manager_dig_ip").value;
    var vusername = document.getElementById("cfg_manager_dig_username").value;
    var vpasswd = document.getElementById("cfg_manager_dig_passwd").value;
    var vport = document.getElementById("cfg_manager_dig_port").value;
    var vurl = document.getElementById("cfg_manager_dig_url").value;
    Live.SetDigitalChannelConfig(parseInt(vchannum), parseInt(vdevicetype), vip, vusername, vpasswd, parseInt(vport), vurl);
  });
  //获取数字通道
  $('#cfg_manager_dig_refresh').on('click', function () {
    if (3 != Live.iLogonState) {
      return;
    }
    var vchannum = $('#cfg_manager_chan').val();
    var r = Live.GetDigitalChannelConfig(parseInt(vchannum));
    if (null == r) {
      return;
    }
    $('#cfg_manager_chan').find("option[value='" + r[0] + "']").prop("selected", "selected");
    $('#cfg_manager_dig_devicetype').find("option[value='" + r[1] + "']").prop("selected", "selected");
    var vip = document.getElementById("cfg_manager_dig_ip");
    vip.value = r[2];
    var vusername = document.getElementById("cfg_manager_dig_username");
    vusername.value = r[3];
    var vpasswd = document.getElementById("cfg_manager_dig_passwd");
    vpasswd.value = r[4];
    var vport = document.getElementById("cfg_manager_dig_port");
    vport.value = r[5];
    var vurl = document.getElementById("cfg_manager_dig_url");
    vurl.value = r[6];
  });

  //字符叠加界面播放视频
  $('#cfg_osd_startplay').on('click', function () {
    //先停止之前的播放
    Cfgosd.Stop();
    //播放主码流
    var chanNo = $("#cfg_osd_channelno").val();	//通道号
    var ret = Cfgosd.Play(chanNo, 0);
    if (null == ret) {
      alert("play failed!");
    }
  });
  //字符叠加界面停止播放视频
  $('#cfg_osd_stopplay').on('click', function () {
    Cfgosd.Stop();
  });

  //设置附加字符
  $('#cfg_osd_addition_save').on('click', function () {
    if (3 != Cfgosd.iLogonState) {
      return;
    }
    var channelno = $('#cfg_osd_channelno').val();
    var vareano = $('#cfg_osd_addition_area').val();
    var vcolor = $('#cfg_osd_addition_color').val();
    var vx = document.getElementById("cfg_osd_addition_x").value;
    var vy = document.getElementById("cfg_osd_addition_y").value;
    var vcontent = document.getElementById("cfg_osd_addition_content").value;
    Cfgosd.SetOsdAdditional(parseInt(channelno), parseInt(vareano), parseInt(vcolor), parseInt(vx), parseInt(vy), vcontent);
    var fontsize = $('#cfg_osd_addtional_size').val();
    if (0 != fontsize) {
      fontsize = (fontsize << 16) | fontsize;
    }
    Cfgosd.SetOsdFontSize(parseInt(channelno), 4, parseInt(fontsize));

  });
  //获取附加字符
  $('#cfg_osd_addition_refresh').on('click', function () {
    if (3 != Cfgosd.iLogonState) {
      return;
    }
    var channelno = $('#cfg_osd_channelno').val();
    var vareano = $('#cfg_osd_addition_area').val();
    var r = Cfgosd.GetOsdAdditional(parseInt(channelno), parseInt(vareano));
    if (null == r) {
      return;
    }
    $('#cfg_osd_addition_area').find("option[value='" + r[0] + "']").prop("selected", "selected");
    $('#cfg_osd_addition_color').find("option[value='" + r[1] + "']").prop("selected", "selected");
    var vx = document.getElementById("cfg_osd_addition_x");
    vx.value = r[2];
    var vy = document.getElementById("cfg_osd_addition_y");
    vy.value = r[3];
    var vcontent = document.getElementById("cfg_osd_addition_content");
    vcontent.value = r[4];

    var frontsize = Cfgosd.GetOsdFontSize(parseInt(channelno), 4);
    if (0 == frontsize) {
      $('#cfg_osd_addtional_size').find("option[value='" + 0 + "']").prop("selected", "selected");
    }
    else {
      var iWidth = (frontsize >> 16) & 0xFF;
      var iHight = frontsize & 0xFF;
      $('#cfg_osd_addtional_size').find("option[value='" + parseInt(iHight) + "']").prop("selected", "selected");
    }
  });

  //设置标题字符叠加
  $('#cfg_osd_title_save').on('click', function () {
    if (3 != Cfgosd.iLogonState) {
      return;
    }
    var channelno = $('#cfg_osd_channelno').val();
    var venable;
    if ($("#cfg_osd_title_enable").is(":checked")) {
      venable = 1;
    } else {
      venable = 0;
    }
    var vtitle = document.getElementById("cfg_osd_title_title").value;
    var vx = document.getElementById("cfg_osd_title_x").value;
    var vy = document.getElementById("cfg_osd_title_y").value;
    var vcolor = $('#cfg_osd_title_color').val();
    Cfgosd.SetOsdTitle(parseInt(channelno), vtitle, parseInt(vx), parseInt(vy), OSDTYPE_TITLE, venable, OSD_CHANNELTITLE, parseInt(vcolor));
  });
  //获取标题字符叠加
  $('#cfg_osd_title_refresh').on('click', function () {
    if (3 != Cfgosd.iLogonState) {
      return;
    }
    var channelno = $('#cfg_osd_channelno').val();
    var r = Cfgosd.GetOsdTitle(parseInt(channelno), OSDTYPE_TITLE, OSD_CHANNELTITLE);
    if (null == r) {
      return;
    }
    var vtitle = document.getElementById("cfg_osd_title_title");
    vtitle.value = r[0];
    var vx = document.getElementById("cfg_osd_title_x");
    vx.value = r[1];
    var vy = document.getElementById("cfg_osd_title_y");
    vy.value = r[2];
    if (0 == parseInt(r[3])) {
      $("#cfg_osd_title_enable").prop("checked", false);
    } else {
      $("#cfg_osd_title_enable").prop("checked", true);
    }
    $('#cfg_osd_title_color').find("option[value='" + r[4] + "']").prop("selected", "selected");
  });

  //设置日期时间字符叠加
  $('#cfg_osd_date_save').on('click', function () {
    if (3 != Cfgosd.iLogonState) {
      return;
    }
    var channelno = $('#cfg_osd_channelno').val();
    var venable;
    if ($("#cfg_osd_date_enable").is(":checked")) {
      venable = 1;
    } else {
      venable = 0;
    }
    var vcolor = $('#cfg_osd_date_color').val();
    var vx = document.getElementById("cfg_osd_date_x").value;
    var vy = document.getElementById("cfg_osd_date_y").value;
    var vshowweek;
    if ($("#cfg_osd_date_showweek").is(":checked")) {
      vshowweek = 1;
    } else {
      vshowweek = 0;
    }
    var vhours = $('#cfg_osd_date_hours').val();
    var vdatetype = $('#cfg_osd_date_datetype').val();
    Cfgosd.SetOsdDate(parseInt(channelno), parseInt(vx), parseInt(vy), OSDTYPE_TIME, venable, OSD_DATETIME, parseInt(vcolor), vshowweek, parseInt(vhours), parseInt(vdatetype));
  });
  //获取日期时间字符叠加
  $('#cfg_osd_date_refresh').on('click', function () {
    if (3 != Live.iLogonState) {
      return;
    }
    var channelno = $('#cfg_osd_channelno').val();
    var r = Cfgosd.GetOsdDate(parseInt(channelno), OSDTYPE_TIME, OSD_DATETIME);
    if (null == r) {
      return;
    }
    var vx = document.getElementById("cfg_osd_date_x");
    vx.value = r[0];
    var vy = document.getElementById("cfg_osd_date_y");
    vy.value = r[1];
    if (0 == parseInt(r[2])) {
      $("#cfg_osd_date_enable").prop("checked", false);
    } else {
      $("#cfg_osd_date_enable").prop("checked", true);
    }
    $('#cfg_osd_date_color').find("option[value='" + r[3] + "']").prop("selected", "selected");
    if (0 == parseInt(r[4])) {
      $("#cfg_osd_date_showweek").prop("checked", false);
    } else {
      $("#cfg_osd_date_showweek").prop("checked", true);
    }
    $('#cfg_osd_date_hours').find("option[value='" + r[5] + "']").prop("selected", "selected");
    $('#cfg_osd_date_datetype').find("option[value='" + r[6] + "']").prop("selected", "selected");
  })


  //Set Device Name
  //$('#btn_device_name_save').on('click', function() {
  //if(3 != Live.iLogonState)
  //{
  //return;
  //}
  //与设备同事确认，目前只支持nvr本地参数设置
  //var chanNo = -1;
  //var devtype = $('#system_dev_ipc_nvr').val();
  //if(2 == parseInt(devtype))
  //{
  //	chanNo = 0x7fffffff;
  //}			
  //else
  //{
  //	chanNo = $("#live_channel_list").val();	//Channel number
  //}
  //var devicename=document.getElementById("system_set_device_name").value;

  //	Live.SetDevName(parseInt(chanNo), devicename);

  //})

  //Set Device Mode
  //$('#btn_device_type_save').on('click', function() {
  //	if(3 != Live.iLogonState)
  //{
  //return;
  //}
  //var chanNo = $("#live_channel_list").val();	//Channel number
  //var devicemode = document.getElementById("system_set_device_type").value;

  //Live.SetDevMode(parseInt(chanNo), devicemode);

  //})
})